<?php 
class Page extends SiteTree {

    public static $db = array();
    
    public static $has_one = array("HeadImage"=>"Image", "BannerImage"=>"Image");
    
    function getCMSFields() {
        $fields = parent::getCMSFields();
        
        //$fields->addFieldToTab("Root.Content.Main", new ImageField("HeadImage", _t("BlogEntry.Image", "Image")),"Content");
        $fields->addFieldToTab("Root.Content.Images", new ImageField('HeadImage'));
        $fields->addFieldToTab("Root.Content.Images", new ImageField('BannerImage'));
        return $fields;
    }
    
}

class Page_Controller extends ContentController {

    public function init() {
        parent::init();
        
        // Note: you should use SS template require tags inside your templates
        // instead of putting Requirements calls here.  However these are
        // included so that our older themes still work
        //		Requirements::themedCSS("layout");
        //		Requirements::themedCSS("typography");
        //		Requirements::themedCSS("form");
    }
    
    /**
     * Site search form
     */
    function SearchForm() {
        $searchText = isset($this->Query) ? $this->Query : 'Search';
        
        $fields = new FieldSet( new TextField("Search", "", $searchText));
        
        $actions = new FieldSet( new FormAction('results', 'Go'));
        
        return new SearchForm($this, "SearchForm", $fields, $actions);
    }

    
    /**
     * Process and render search results
     */
    function results($data, $form){
      $data = array(
         'Results' => $form->getResults(),
         'Query' => $form->getSearchQuery(),
         'Title' => 'Search Results'
      );
      $this->Query = $form->getSearchQuery();
	  
      return $this->customise($data)->renderWith(array('Page_results', 'Page'));
   }

    
}

?>
